package cn.blnp.net.flowable.task.user;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * <h3></h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/12 15:28
 */
@Component
public class UserTaskListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        switch (delegateTask.getTaskDefinitionKey()){
            case "userTask1": //为用户任务userTask1设置办理人
                delegateTask.setAssignee("baby");
                break;
            case "userTask2": //为用户任务userTask2设置候选人
                List<String> candidateUsers = Arrays.asList("user1","user2");
                delegateTask.addCandidateUsers(candidateUsers);
                break;
            case "userTask3": //为用户任务userTask3设置候选组
                List<String> candidateGroups = Arrays.asList("group1","group2");
                delegateTask.addCandidateGroups(candidateGroups);
                break;
            case "userTask4": //为用户任务userTask4设置办理人
                String designatedUserName
                        = (String)delegateTask.getVariable("designatedUserName");
                delegateTask.setAssignee(designatedUserName);
                break;
        }
    }
}
